<?php

require_once(dirname(__FILE__) . '/appconf.php');

class Aax_points extends Site {

    function setup() {
        $this->run_modes('ajax_share_report_points', 'is_login','ajax_fb_points');
        $this->start_mode('points_action');
        parent::setup();
    }

    function cgiapp_prerun($rm = '') {
        $this->Points = getModel('Model_Points');
        parent::cgiapp_prerun();
    }

    function action_ajax_fb_points() {

        //ret=2 未登錄

        $code = $this->get_q("code");
        $action = $this->get_q("action_name");
        $remark = $this->get_q("remark");
        //$id = $this->get_q("id");
        $member = $this->s_param('memberData');

        $json_array = array();
        $uid = $member['id'];
        if ($uid) {
            if (md5($_SERVER['HTTP_REFERER'] . "imoreHK") == $code && $action) {
                $ret = $this->Points->points_record($uid, $action, $remark);
                $json_array = array('ret' => 1, 'reason' => '成功', 'data' => $ret);
               // $sql = 'update product_reports set  fb_share_num=fb_share_num+1 where id=' . $id;
                //db_handle($sql);
                
            } else {
                $json_array = array('ret' => 0, 'reason' => 'code出錯');
            }
        } else {
            $json_array = array('ret' => 2, 'reason' => '未登入');
        }
        echo json_encode($json_array);
    }

    function action_is_login() {
        $member = $this->s_param('memberData');
        if ($member) {
            $json_array = array('ret' => 1, 'reason' => '已登入');
        } else {
            $json_array = array('ret' => 2, 'reason' => '未登入');
        }

        echo json_encode($json_array);
    }

}

$webapp = new Aax_points();
$webapp->run();
?>